<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>余票查询</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<style>
		    .button{
				height:45px;
				margin-top: 7%;
				margin-bottom: 7%;
		    }
			.mui-btn {
				width: 100%;
				height:50px;
				font-size: 25px;
			}
			.myList {
			    background: url(../img/arrow_down.png) right center no-repeat; 
			    width: 150%;
			    overflow: hidden;
			    border: solid 1px #ccc;
			    margin-left: -60%;
			    margin-right: -10%;
			   
			}
			#myList{
			    -webkit-appearance:none;
			    -moz-appearance:none;
			    appearance:none;
			    background:transparent;
			    border:none;
			    padding-left:5%;
			    margin-bottom: -10%;
			    margin-top: -5%;
			    position:relative;
			}
		</style>
	</head>

	<body >
		<div class="mui-content">
		    <ul class="mui-table-view">
		        <li class="mui-table-view-cell" style="margin-right: 4%;">
		             <div class="mui-table" style="font-size: 14px;">
						<div  class="mui-table-cell mui-col-xs-2 ">
							<div >出发地：</div>
						</div>
						<div  class="mui-table-cell mui-col-xs-2 ">
							<button id="start_station_name" style="margin-left: -20%;;width: 100%; margin-top:-2%;">合肥</button>
					    </div>
					   <div  class="mui-table-cell mui-col-xs-2 ">
							<div style="margin-left: 10%;">目的地：</div>
						</div>
						<div  class="mui-table-cell mui-col-xs-2 ">
							 <button id="end_station_name" style="margin-left: -20%;width: 100%; margin-top:-2%;">北京</button>
					    </div>
					</div>           
		        </li>
		        <li class="mui-table-view-cell" style="margin-right: 4%;">
		             <div class="mui-table" style="font-size: 14px;">
						<div class="mui-table"  >
							<div class="mui-table-cell mui-col-xs-2">
								乘车日期：	
							</div>
							<div  class="mui-table-cell mui-col-xs-2 " style="">
								<div style="margin-left: -45%;">
									<button id="date_time"  style="margin-top: -6%;margin-bottom: -3%;width:80%;">
										<!--<font style="font-size: 18px;">2016-06-14</font>
										<img src="../../img/calendar.png" style="margin:-2% 0 -4% 10%; "/>-->
									</button>
								</div>
						    </div>
						</div>      
					    <div  class="mui-table-cell mui-col-xs-2 ">
							<div style="margin-left:-40%;">类型：</div>
						</div>
						<div  class="mui-table-cell mui-col-xs-2 ">
							<div class="mui-card myList "  >
								<select id="myList" name="myList"  onchange="favBrowser()">
									<option value="0" >成人票</option>
									<option value="1">学生票</option>
								</select>
							</div>
					   </div>
					</div>           
		        </li>
		    </ul>
		    <div class="mui-content-padded" align="center">
		        <button id="Select" type="button" class="mui-btn mui-btn-blue ">查询</button>
	        </div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/guide.js" ></script>
		<script type="text/javascript" src="../js/date_time.js" ></script>
		<script type="text/javascript" language="JavaScript">
		    var type="成人票";
		    var type_node;
		    var time;
		    var flag;
			mui.init()
			mui.plusReady(function(){
				var start_station_name=document.getElementById("start_station_name");
				var end_station_name=document.getElementById("end_station_name");
				var date_time=document.getElementById("date_time");
				
				var passmessage_type=document.getElementById("passmessage_type");
				
				//取出本地的存储值并赋值
				if (localStorage.getItem('queryTicket_start_station_name')) {
					start_station_name.innerHTML= localStorage.getItem('queryTicket_start_station_name');
				}
				if (localStorage.getItem('queryTicket_end_station_name')) {
					end_station_name.innerHTML= localStorage.getItem('queryTicket_end_station_name');
				}
			    date_time.innerHTML=set_dateTime(get_date_time()); 
				
				
				//点击出发地按钮，选择出发地
				start_station_name.addEventListener('tap', function() {
					var address="guide/queryTicket_needtem.html";  // 返回数据时的地址
					mui.openWindow({
						url: '../html/station.html',
						id: 'station',
						extras: {
							station: "出发地", //将出发站的title传过去
							address: address ,
							title:"余票查询"
						}
					});
				});
				
				
				//点击目的地按钮，选择目的地
				end_station_name.addEventListener('tap', function() {
					var address="guide/queryTicket_needtem.html";  // 返回数据时的地址
					mui.openWindow({
						url: '../html/station.html',
						id: 'station',
						extras: {
							station: "目的地",   //将出发站的title传过去
							address: address,  
							title:"余票查询"
						}
					});
				});
				
				
				date_time.addEventListener('tap', function() {
					flag=true;
					console.log("请选择日期---->"+flag);
					mui.openWindow({
						url: '../html/calendar.html',
						id: '../html/calendar.html',
						extras:{
							data : "guide/queryTicket_needtem.html",
							title:"余票查询",
						}
				    });
				});
				
				var currentWebview = plus.webview.currentWebview();
				var parentWebview = currentWebview.parent();
				mui.fire(parentWebview ,'getCategoryID',{});
				//接收data_time数据
				window.addEventListener('postCategoryID',function(e){
				    if(typeof(e.detail.data_time)!="undefined")
					    date_time.innerHTML=set_dateTime(e.detail.data_time);
					if(typeof(e.detail.station_name)!="undefined"){  //如果在选择车站时，没有点击任何时间值，则返回的值为空
		                if(e.detail.title_name=="出发地"){
		                	start_station_name.innerHTML=e.detail.station_name;
		                	localStorage.setItem('queryTicket_start_station_name',e.detail.station_name);
		                }else if(e.detail.title_name=="目的地"){
		                	end_station_name.innerHTML=e.detail.station_name;
		                	localStorage.setItem('queryTicket_end_station_name',e.detail.station_name);
		                }
		                 
		           }
			   });
				
			
				var Select=document.getElementById("Select");
				Select.addEventListener('tap', function() {
					if(type=="成人票"){
						type_node="ADULT";
					}else if(type=="学生票"){
						type_node="0X00";
					}
					ajax_queryTicket({
						purpose_codes : type_node,
                        queryDate : time,
                        from_station : start_station_name.innerHTML,
                        to_station : end_station_name.innerHTML
					}); 
				});
				
			})
			
			//填充乘车日期
			function set_dateTime(data){
				time=data;
				console.log(data);
				var list='';
				list=list+  '<font style="font-size: 14px;">'+data+'</font>'+
							'<img src="../img/calendar.png" style="margin:-2% 0 -4% 10%; "/>';
				return list;
			}
			
			
			//申请数据成功，跳转到下一页面
			function queryTicketSuccess(data){
				if(data.result.status==true){
					if(data.result.data.flag==false){
						alert(data.result.data.message);
					}else{
						mui.openWindow({
							url: 'queryTicketDetail.html',
							id: 'queryTicketDetail.html',
							extras:{
								data : data,
								from_station : start_station_name.innerHTML,
								to_station : end_station_name.innerHTML,
							}
					    });
					}
				};
			}
			
			
			//获取下拉菜单中的点击数据
			function favBrowser(){
				var mylist=document.getElementById("myList");
                type=mylist.options[mylist.selectedIndex].text;
			}
		</script>
	</body>

</html>